package com.hcms.admin.controller.cms;

import com.hcms.admin.annotation.CheckPermission;
import com.hcms.admin.dto.CmsModuleOptionResponse;
import com.hcms.admin.service.ICmsModuleService;
import com.hcms.common.api.CommonPage;
import com.hcms.common.api.CommonResponse;
import com.hcms.mybatis.entity.CmsModule;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 模块配置表 前端控制器
 * </p>
 *
 * @author achenxw@126.com
 * @since 2023-04-01
 */
@Api("模块管理")
@RestController
@RequestMapping("/cmsModule")
public class CmsModuleController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    ICmsModuleService cmsModuleService;

    @ApiOperation("获取记录")
    @GetMapping("")
    @ResponseBody
    public ResponseEntity<CommonResponse<CommonPage<CmsModule>>> index(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        logger.info("Run index(), pageNum={}, pageSize={}", pageNum, pageSize);
        List<CmsModule> list = cmsModuleService.getList(pageNum, pageSize);
        return CommonResponse.ok(CommonPage.restPage(list));
    }

    @GetMapping("/options")
    @ResponseBody
    @CheckPermission(check = false)
    public ResponseEntity<CommonResponse<List<CmsModuleOptionResponse>>> options() {
        List<CmsModuleOptionResponse> options = cmsModuleService.getOptions();
        return CommonResponse.ok(options);
    }

}
